﻿var fckEditPath = 'jslab/FCK_Editor/' ;
var loginMniUrl = root_path+'?option=loginMini';
var checkLoginUrl = root_path+'?option=checkUserLoginAJAX';
var saveErrorUrl = root_path +'?option=saveFrontError';
var loginType = 'normal';
var aspectRatioc = 1; // crop


var Tag_Max_Length = 20;
var Tag_Max_Num = 6;

if(!splitString)
	var splitString = '[QQ:13640661][julying.com][王子墨]';






hs.graphicsDir = root_path +'jslab/highslide/graphics/';
hs.outlineType = 'drop-shadow';
hs.wrapperClassName = 'draggable-header' ;


window.onerror = saveError;
function saveError(error,url,line){
	$.post(saveErrorUrl,{error:error,url:url,line:line});
}


$(function(){	 
	 //为所有页面的body元素内增加一个div.wrapper容器，以便控制样式，袁20101009
	
		 /*$('body').wrapInner('<div class="wrapper" />');*/
	/*	 if(!$("div.wrapper")){ }*/
	 
	//screenScroll('#nav');
	inputChangeTitle('#searchTag');
	
	$('#searchForm').submit(function(){
		if( $('#searchTag').val() == $('#searchTag').attr('defaultVal') || $('#searchTag').val() == '')
			return false;
	});
	
	//增加shiningbox高亮效果
	$('.shiningTFD').focus(function(){
		$(this).addClass("highLight");						  
	}).blur(function(){									  
		$(this).removeClass("highLight");
	});
	
	$('#logout').click(function(){
		if(!affirm('确定退出吗？'))
			return false;
	});
	
	var $contents = $('div.pos div.contents') ;
	var contentsH = $contents.height() ;
	var navH = 350;
	if( contentsH < navH ) $contents.height(navH);
	

	
	$('#footer').corner('8px bottom');
});

function getMenu(obj){
	var tagMenu = '';
	$obj=$(obj);
	$obj.find('.tagMenu').each(function(){
		var name= $(this).find('label').attr('ids');
		var menu = '';
		$(this).find('a').each(function(){
			if($(this).hasClass('active') && !($(this).hasClass('all')) && $(this).attr('ids') )
				menu += ','+ $(this).attr('ids');
		});
		tagMenu += '|'+ name + '!' + menu.replace(',','') ;
	});
	tagMenu = tagMenu.replace('|','');
	return tagMenu;
}


function getCustomMenu(obj){
	var tagMenu = '';
	$(obj).each(function(){
		tagMenu += ','+ $(this).html();	
	});
	tagMenu = tagMenu.replace(',','');
	return tagMenu ;
};



function isLogin(){
	if( null != $.cookie('user_id') )
		return true;
	else
		return false;
};

function openLogin(obj){
	var id ='open_'+(new Date()).valueOf() ;
	var a ='<a id="'+id+'" class="openDig" href="'+loginMniUrl+'" target="_blank" onclick="return hs.htmlExpand(this,{objectType:\'iframe\'})"></a>';
	if(!obj) obj = 'body';
	$(obj).before(a);
	$('#'+id).click();
};

function statusCheck(data,obj){
	if(  data.detail == 'noLogin'){
		openLogin(obj);
		return false;
	};
}

function loginMiniSuccess(){
	hs.close();
	setTimeout(function(){window.parent.location.reload();},1000);
};

function beautyImg(obj){
	$(obj).beautyStyle({'type':'img'});
}

function beauty(obj){
	$(obj).beautyStyle({'align':'center'});
};


//Tag_Max_Num = 5 ; Tag_Length = 12 ;  -->  config

function addTag(inputObj,addSubmitObj,listObj){
	$(inputObj)//.blur(function(){$(addSubmitObj).get(0).click(); })
	.keypress(function(e){ 
		if(e.keyCode == 13 || e.keyCode == 10){
			$(addSubmitObj).get(0).click();
			return false;
		}
	});
	
	$(addSubmitObj).click(function(){
		var Tag = null ;
		var exits_Tag = false;
		Tag = $(inputObj).val().replace(/\s/g,'');
		if( Tag != '' ){
			if( checkBanChar(Tag) ){$.openWin({'msg':'标签中<span class="high">不允许特殊符号</span> ','status':'error'}); return false; }				
			$(listObj).find('a').each(function(){
				if( Tag == $(this).attr('Tag') ) { exits_Tag = true ;	}	
			});			
			if( !exits_Tag ){
				if( stringLen($(inputObj).val()) > Tag_Max_Length  ){
					$.openWin({'msg':'请缩短标签长度。 现在标签长度为:<span class="high">'+stringLen($(inputObj).val())+'</span>.。标签长度必须小于等于<span class="high">'+ Tag_Max_Length +'</span>','status':'warn'});
					return false;
				}
				if( $(listObj).find('a').size() >= Tag_Max_Num  ){
					$.openWin({'msg': '最多只允许( <span class="high">' + Tag_Max_Num +'</span> )个标签','status':'error' });
					$(inputObj).val('');
					return false;
				}
				$(listObj).append('<a onclick="remove(this);return false;" Tag="'+ Tag +'">'+ Tag +'</a>');
				$(inputObj).val('');
				return false;
			}else{
				$(inputObj).val('');
				//$.openWin({'msg':'"'+Tag +'" 标签<span class="high">已经存在</span>','time':2000});return false;
			}			
		}
		return false;
	});
};


function delFile(obj,goUrl,msg){
	if(!msg) msg = '如果删除作品，所有与该作品相关的评论和统计等数据都将删除，你确实要删除么？';
	$(obj).click(function(){
		if(affirm(msg)){
			var $a = $(this);
			$.post($(this).attr('href')+'&dataType=ajax',function(data){
				if(data.status == 'ok'){
					$.openWin({'msg':data.msg,'time':1500, 'bg':false});
					$a.parent().parent().parent().remove();
					if(goUrl) setTimeout(function(){ window.location.href = goUrl},1800);
					setTimeout(function(){
						if( $(obj).length == 0 ) window.location.reload();
					},2000);
					
				}else{
					alert(data.msg );
				}
			},'json');
		}
		return false;
	});
}

function changeFileStatus(obj){
	$(obj).click(function(){
		var $a = $(this);
		$.post($(this).attr('href')+'&dataType=ajax',function(data){
			if(data.status == 'ok'){
				$.openWin({'msg':data.msg,'time':1500, 'bg':false});
			}else{
				alert(data.msg);
			}
		},'json');
		return false;
	});
}



function affirm(msg){
	ht = document.getElementsByTagName("html");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if(typeof(msg)=='undefined') msg = '要退出吗？';
	if (confirm(msg)){	  
	  ht[0].style.filter = "";	  
	  return true;
	}else{
	  ht[0].style.filter = "";
	  return false;
	}
}

function creatIframe(obj){
	$(obj).click(function(){
		hs.htmlExpand(this, { objectType: 'iframe' } );
		return false;
	});
}